from django.shortcuts import render, HttpResponse
from django.http import HttpResponse
from .tasks import add
from datetime import datetime


from .tasks import send_email
def first_celery(request):
    #任务函数的异步调用
    send_email.delay(request.data['email'])
    return HttpResponse("OK")

def test(request):
    # 将my_task任务加入到celery队列中
    # 如果my_task函数有参数，可通过delay()传递
    # 例如 my_task(a, b), my_task.delay(10, 20)
    result = add.delay(2, 3)
    print(result)
    #  ctime = datetime.now()
    #  # 默认用utc时间
    #  utc_ctime = datetime.utcfromtimestamp(ctime.timestamp())
    #  from datetime import timedelta
    #
    #  time_delay = timedelta(seconds=5)
    #  task_time = utc_ctime + time_delay
    #  add.apply_async(args=[4, 3], eta=task_time)
    return HttpResponse("<h1>服务器返回响应内容!</h1>")
